package cn.com.bluemoon.daps.standard.vo;

import cn.afterturn.easypoi.excel.annotation.Excel;
import cn.afterturn.easypoi.excel.annotation.ExcelCollection;
import cn.com.bluemoon.daps.standard.dto.ExcelImportGroup;
import cn.com.bluemoon.daps.standard.dto.IndStdExcelDataStandardDto;
import cn.com.bluemoon.daps.standard.dto.IndStdExcelIndexCaliberDto;
import cn.com.bluemoon.daps.standard.dto.IndStdExcelStatisticalCaliberDto;
import cn.com.bluemoon.daps.standard.entity.DapStandardIndex;
import cn.com.bluemoon.daps.standard.util.GsonExclusionField;
import com.baomidou.mybatisplus.annotation.TableField;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.google.common.collect.Lists;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import org.springframework.beans.BeanUtils;

import javax.validation.constraints.NotBlank;
import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.List;

import static org.apache.commons.lang3.builder.ToStringBuilder.reflectionToString;
import static org.apache.commons.lang3.builder.ToStringStyle.MULTI_LINE_STYLE;

/**
 * @author Jarod.Kong
 * @date 2020/8/10 10:59
 */
@Setter
@Getter
public class IndexStandardVo extends DapStandardIndex implements Serializable {

    @TableField(exist = false)
    @Excel(name = "*主题")
    @NotBlank(message = "主题不可为空", groups = {ExcelImportGroup.class})
    private String topicName;

    @TableField(exist = false)
    @Excel(name = "*一级分类")
    @NotBlank(message = "一级分类不可为空", groups = {ExcelImportGroup.class})
    private String firstCategoryName;

    @TableField(exist = false)
    @Excel(name = "二级分类")
    private String secondCategoryName;

    @TableField(exist = false)
    @Excel(name = "三级分类")
    private String thirdCategoryName;

    @TableField(exist = false)
    @Excel(name = "*归口管理部门")
    private String departmentName;

    @TableField(exist = false)
    @ApiModelProperty(value = "数据源系统名称")
    private String dataSourceSystemName;

    @ApiModelProperty(value = "业务线名称")
    @Excel(name="*业务线")
    private String bizLine;

    @TableField(exist = false)
    private List<ReportInfo> reportInfos = Lists.newArrayList();

    @ExcelCollection(name = "指标口径-确认")
    @GsonExclusionField
    private List<IndStdExcelIndexCaliberDto> indexCaliberDtos = Lists.newArrayList();

    @ExcelCollection(name = "数据规范")
    @GsonExclusionField
    private List<IndStdExcelDataStandardDto> dataStandardDtos = Lists.newArrayList();

    @ExcelCollection(name = "统计口径")
    @GsonExclusionField
    private List<IndStdExcelStatisticalCaliberDto> statisticalCaliberDtos = Lists.newArrayList();

    /**
     * {@link this#getRelatedIndex()}
     */
    @ApiModelProperty("关联指标名称")
    private String relatedIndexNames;

    @ApiModelProperty("关联维度名称")
    private String associationDimensionNames;

    /**
     * 新需求：增加指标类型属性：原子指标、派生指标、计算指标；
     * 影响属性：关联指标，原子指标没有关联指标
     */
    @ApiModelProperty("指标类型, 1原子指标、2派生指标、3计算指标")
    private String indexTypeName;

    @ApiModelProperty("指标表与模型id关系表")
    private IndexStandardRelateDwModelVo indexStandardRelateDwModelVo;

    private MetaDataTableInfoVO metaDataTableInfoVO;

    public IndexStandardVo() {
    }

    public IndexStandardVo(DapStandardIndex index) {
        if (index != null) {
            BeanUtils.copyProperties(index, this);
        }
    }

    public static String indexTypeToName(Integer indexType){
        if (indexType == null) {
            return null;
        }
        if (indexType == 1){
            return "原子指标";
        }
        if (indexType == 2){
            return "派生指标";
        }
        if (indexType == 3){
            return "计算指标";
        }
        return null;
    }
    @Override
    public String toString() {
        return reflectionToString(this, MULTI_LINE_STYLE);
    }

    @Data
    @GsonExclusionField
    public static class ReportInfo implements Serializable {
        private static final long serialVersionUID = 1L;
        @ApiModelProperty(
                name = "报表名称"
        )
        private String reportName;
        @ApiModelProperty(
                name = "报表路径"
        )
        private String reportPath;
        @ApiModelProperty(
                name = "系统名称"
        )
        private String systemName;
        @ApiModelProperty(
                name = "关联表"
        )
        private String associativeTable;
        @ApiModelProperty(
                name = "报表描述"
        )
        private String reportComment;
        @ApiModelProperty(
                name = "更新时间"
        )
        private String updateTime;

    }
}
